// 模块：生产计划，生产任务，工序管理
import axios from 'axios'
const modelUrl = '/produce'
// 生产计划
export interface ProductionPlanReq {
  prodPlanId?: string
  prodPlanCode?: string
  saleOrderId: string
  productId: string
  qty?: number
  planProdQty: number
  saleOrderCode: string
  productName?: string
  unit?: string
  prodFlowCode?: string[]
  processIdList?: string[]
  deliveryDate: string
  remark: string
  specModel?: string
  detailList: {
    materialStockId: string
    qty: number
    spec: string
    unit: string
    materialCode: string
    fluteType: string
    outboundStatus: number
    crimpLine: string
    materialName: string
  }[]
}
export interface ProductionPlanRes {
  currentPage?: number
  pageSize?: number
  totalPage?: number
  totalCount?: number
  list: ProductionPlanResItem[]
}
export interface ProductionPlanResItem {
  prodPlanId: string
  prodPlanCode: string
  customerName?: string
  saleOrderId: string
  saleOrderCode: string
  productId: string
  productName: string
  spec: string
  unit: string
  prodFlowCode: string[]
  planProdQty: number
  processIdList: string[]
  deliveryDate: string
  remark: string
  productCategory: string
  specModel: string
  materialName: string
  materialCode: string
  materialDesc: string
  fluteType: string
  crimpLine: string
  processNameList: string[]
  createdBy: string
  createdDt: string
  updatedBy: string
  updatedDt: string
  prodPlanDetailId?: string
  materialStockId?: string
  detailList: {
    prodPlanDetailId: string
    prodPlanId: string
    materialStockId: string
    materialName: string
    materialCategory: string
    spec: string
    materialCode: string
    materialDesc: string
    fluteType: string
    boxSpec: string
    crimpLine: string
    unit: string
    qty: number
    outboundStatus: number
  }[]
  processContent?: string[]
  qty: number
  index?: number // 导出的序号
}
export interface HandleProductionPlanResItem {
  prodPlanId: string
  prodPlanCode: string
  saleOrderId: string
  saleOrderCode: string
  productId: string
  productName: string
  spec: string
  unit: string
  prodFlowCode: string[]
  planProdQty: number
  processIdList: string[]
  deliveryDate: string
  remark: string
  productCategory: string
  specModel: string
  materialName: string
  materialCode: string
  materialDesc: string
  fluteType: string
  crimpLine: string
  processNameList: string[]
  processNames?: string
  createdBy: string
  createdDt: string
  updatedBy: string
  updatedDt: string
  prodPlanDetailId?: string
  materialStockId?: string
  material?: {
    prodPlanDetailId?: string
    prodPlanId?: string
    materialStockId?: string
    materialName?: string
    materialCategory?: string
    spec?: string
    materialCode?: string
    materialDesc?: string
    fluteType?: string
    boxSpec?: string
    crimpLine?: string
    unit?: string
    qty?: number
    outboundStatus?: number | string
  }
  processContent?: string[]
  qty: number
  index?: number // 导出的序号
  detailList: {
    prodPlanDetailId: string
    prodPlanId: string
    materialStockId: string
    materialName: string
    materialCategory: string
    spec: string
    materialCode: string
    materialDesc: string
    fluteType: string
    boxSpec: string
    crimpLine: string
    unit: string
    qty: number
    outboundStatus: number
  }[]
}
export interface ProductionPlanListSearch {
  saleOrderId?: string
  productId?: string
  qty?: number
  planProdQty?: number
  saleOrderCode?: string
  productName?: string
  unit?: string
  prodFlowCode?: string
  processContent?: string
  deliveryDate?: string[]
  deliveryStartDate?: string
  deliveryEndDate?: string
  remark?: string
}
export interface materialOutWarehouseReq {
  materialStockId: string
  stockQty: number
  prodPlanDetailId: string
}
export function editProductionPlan(data: ProductionPlanReq) {
  return axios.post<ProductionPlanRes>(modelUrl + '/prodPlanAdit', data)
}

export function delProductionPlan(data: { prodPlanId: string }) {
  return axios.post<object>(modelUrl + '/prodPlanDel', data)
}

export function getProductionPlanDetail(data: { prodPlanId: string }) {
  return axios.post<ProductionPlanResItem>(modelUrl + '/prodPlanDetail', data)
}

export function getProductionPlanAllList(data?: ProductionPlanListSearch) {
  return axios.post<ProductionPlanRes>(modelUrl + '/prodPlanList', data)
}

export function getProductionPlanPageList(data?: ProductionPlanListSearch) {
  return axios.post<ProductionPlanRes>(modelUrl + '/prodPlanPage', data)
}

export function batchAddProductionPlan(data?: ProductionPlanReq[]) {
  return axios.post<ProductionPlanRes>(modelUrl + '/prodPlanBatchAdd', data)
}

// 原材料出库
export function materialOutWarehouse(data: materialOutWarehouseReq[]) {
  return axios.post<ProductionPlanRes>('produce/prodPlanMaterialStockAdd', data)
}

export function batchDelProdPlan(data?: { idList: string[] }) {
  return axios.post<ProductionPlanRes>(modelUrl + '/prodPlanDelBatch', data)
}

// 工序及设备
export interface ProcessReq {
  processId?: string
  processName: string
  mainDirectorId: string
  deputyDirectorIdList: string[]
}
export interface ProcessRes {
  currentPage?: number
  pageSize?: number
  totalPage?: number
  totalCount?: number
  list: ProcessResItem[]
}
export interface ProcessResItem {
  processId?: string
  processName: string
  index?: number // 导出的序号
  mainDirectorId: string
  deputyDirectorIdList: string[]
  mainDirectorName: string
  deputyDirectorNameList: string[]
  deputyDirectorNames: string // 导出用
}
export interface ProcessListSearch {
  processId?: string
  processName?: string
}
export function editProcess(data: ProcessReq) {
  return axios.post<ProcessRes>(modelUrl + '/processAdit', data)
}

export function delProcess(data: { processId: string }) {
  return axios.post<object>(modelUrl + '/processDel', data)
}

export function getProcessDetail(data: { processId: string }) {
  return axios.post<ProcessRes>(modelUrl + '/processDetail', data)
}

export function getProcessAllList(data?: ProcessListSearch) {
  return axios.post<ProcessRes>(modelUrl + '/processList', data)
}

export function getProcessPageList(data?: ProcessListSearch) {
  return axios.post<ProcessRes>(modelUrl + '/processPage', data)
}

export function batchDelProcess(data: { idList: string[] }) {
  return axios.post<ProcessRes>(modelUrl + '/processDelBatch', data)
}

// 生产任务
export interface ProductionFinishReq {
  prodFlowId?: string
  prodPlanId?: string
  prodPlanCode: string
  productId: string
  planQty: number
  productQty: number
  totalLossRate: number
  remark: string
  inbounderld?: string
  materialQty: number
  detailList: {
    processId: string
    qty: number
    lossRate: number
    mainDirectorId?: string
    mainDirectorName?: string
    deputyDirectorIdList?: string[]
    deputyDirectorNameList?: string[]
  }[]
}
export interface ProductionFinishRes {
  currentPage?: number
  pageSize?: number
  totalPage?: number
  totalCount?: number
  list: ProductionFinishResItem[]
}
export interface ProductionFinishResItem {
  span?: number
  index?: number // 导出的序号
  prodFlowId: string
  prodFlowCode: string
  prodPlanCode: string
  productId: string
  planQty: number
  productQty: number
  totalLossRate: number
  remark: string
  productName: string
  processDataList?: any
  prodFlowDetialId?: string
  spec: string
  specModel: string
  materialQty: number
  detailList: {
    prodFlowDetialId: string
    prodFlowId: string
    processId: string
    qty: number
    lossRate: number
    directorBy: string
    processName: string
  }[]
}
export interface ProductionFinishListSearch {
  prodFlowCode?: string
  productId?: number
  productName?: string
  planQty?: number
  productQty?: number
  totalLossRate?: number
  remark?: string
  tenantId?: number
}
export interface ProductionInWarehouseReq {
  materialName: string
  spec: string
  stockQty: number
  prodFlowId: string
}
export interface batchProductionFinishReq {
  prodFlowId?: string
  prodPlanId: string
  prodPlanCode: string
  productId?: string
  planQty?: number
  productQty?: number
  totalLossRate?: number
  remark?: string
  inbounderId?: string
  detailList: ProductionFinishReq['detailList']
}

export function editProFinish(data: ProductionFinishReq) {
  return axios.post<ProductionFinishRes>(modelUrl + '/prodFlowAdit', data)
}

export function delProFinish(data: { prodFlowId: string }) {
  return axios.post<object>(modelUrl + '/prodFlowDel', data)
}

export function getProFinishDetail(data: { prodFlowId: string }) {
  return axios.post<ProductionFinishResItem>(modelUrl + '/prodFlowDetail', data)
}

export function getProFinishAllList(data?: ProductionFinishListSearch) {
  return axios.post<ProductionFinishRes>(modelUrl + '/prodFlowList', data)
}

export function getProFinishPageList(data?: ProductionFinishListSearch) {
  return axios.post<ProductionFinishRes>(modelUrl + '/prodFlowPage', data)
}

// 入库
export function productInWarehouse(data: ProductionInWarehouseReq[]) {
  return axios.post<ProductionFinishRes>('produce/prodFlowMaterialStockAdd', data)
}
// 批量新增
export function prodFlowBatchAdd(data: batchProductionFinishReq[]) {
  return axios.post<ProductionFinishResItem>('produce/prodFlowBatchAdd', data)
}

export function batchDelProdFinish(data?: { idList: string[] }) {
  return axios.post<ProductionPlanRes>(modelUrl + '/prodFlowDelBatch', data)
}
